﻿using System.Collections.Generic;
using BoldBrick.OneIntranet.HR.DataObjects.Lists.PositionsListData.Views;
using BoldBrick.OneIntranet.HR.Resources;
using BoldBrick.SharePoint.CommonControls.DataObjects.Base;
using Microsoft.SharePoint;

namespace BoldBrick.OneIntranet.HR.DataObjects.Lists.PositionsListData
{
	/// <summary>
	/// Metadata class of "Positions" list
	/// </summary>
	public class PositionsList : BaseList
	{
		#region ------ Columns --------------------------------------------------------------------

		public ListColumn PositionNameWithMenuColumn
		{
			get { return SiteColumns.PositionNameWithMenuColumn; }
		}

		public static ListColumn PositionNameColumn
		{
			get { return SiteColumns.PositionNameColumn; }
		}

		public static ListColumn PositionNameNoMenuColumn
		{
			get { return SiteColumns.PositionNameNoMenuColumn; }
		}

		#endregion

		#region ------ Views ----------------------------------------------------------------------

		private OpenedPositionsView openedPositionsView;
		public OpenedPositionsView OpenedPositionsView
		{
			get
			{
				if (openedPositionsView == null)
					openedPositionsView = new OpenedPositionsView();
				return openedPositionsView;
			}
		}

		private ArchivedPositionsView archivedPositionsView;
		public ArchivedPositionsView ArchivedPositionsView
		{
			get
			{
				if (archivedPositionsView == null)
					archivedPositionsView = new ArchivedPositionsView();
				return archivedPositionsView;
			}
		}

		public override ViewsCollection GetViews()
		{
			ViewsCollection viewsCollection = new ViewsCollection
			                                  	{
			                                  		this.OpenedPositionsView,
													this.ArchivedPositionsView
			                                  	};
			return viewsCollection;
		}

		#endregion

		public PositionsList()
		{
			this.EnableFolderCreation = true;
		}

		protected override string GetListTitleResourceKey()
		{
			return "List_Positions_Title";
		}

		protected override string GetListNameResourceKey()
		{
			return "List_Positions_Name";
		}

		protected override SPListTemplateType? GetListTemplateType()
		{
			return SPListTemplateType.GenericList;
		}

		public override List<BaseContentType> GetContentTypes()
		{
			List<BaseContentType> contentTypes = new List<BaseContentType>
			                                     	{
			                                     		ContentTypes.ContentTypes.PositionContentType,
														SharePoint.CommonControls.DataObjects.ContentTypes.ContentTypes.FolderContentType
			                                     	};

			return contentTypes;
		}

		protected override void OnAfterContentTypesUpdated(SPWeb web, SPList list)
		{
			base.OnAfterContentTypesUpdated(web, list);

			string validationFormula = string.Format("=[{0}]<=[{1}]",
							SiteColumns.SalaryRangeFromColumn.GetDisplayName(web.Language),
							SiteColumns.SalaryRangeToColumn.GetDisplayName(web.Language));
			string validationMessage = ResourceBuilder.GetResource("List_Position_Validation_Message", web.Language);
			list.ValidationFormula = validationFormula;
			list.ValidationMessage = validationMessage;
		}

	}
}
